package com.jump.userweb.controller.v1;

import com.jump.userweb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * Created by fangxiao on 15/9/7.
 */
@RestController
@RequestMapping("/user/rest/v1")
public class UserRestController {

    @Autowired
    UserService userService ;

    @RequestMapping(value = "/existusername/{username}", method=RequestMethod.GET)
    public Map existUserName(@PathVariable String username) {
        RestTemplate rs = new RestTemplate();
        Map map  = (Map)rs.getForObject("http://localhost:8080/user/v1/existusername/" + username,
                Map.class
        );

        return map;
    }



    @RequestMapping(value="/register", method=RequestMethod.POST)
    public Map doRegister(@RequestParam String userName,
                             @RequestParam String mobile,
                             @RequestParam String password,
                             @RequestParam String email) {
        Map map = userService.getRegisterMap(userName, password, mobile, email);
        return map;
    }



}
